﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using GalaSoft.MvvmLight;

namespace SoGame.Controls
{
    public class DialogBoxBase : Window, IDialogBox
    {
        static  DialogBoxBase()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(DialogBoxBase), new FrameworkPropertyMetadata(typeof(DialogBoxBase)));
        }

        public DialogBoxBase()
        {
            WindowStyle = WindowStyle.None;
            AllowsTransparency = true;
            ResizeMode = ResizeMode.NoResize;
            Style = Application.Current.Resources["DialogBoxBase"] as Style;
            WindowStartupLocation = WindowStartupLocation.Manual;

            Height = Application.Current.MainWindow.Height;
            Width = Application.Current.MainWindow.Width;
            Top = Application.Current.MainWindow.Top;
            Left = Application.Current.MainWindow.Left;

            Owner = Application.Current.MainWindow;
            Loaded += DialogBoxBase_Loaded;   
        }

        void DialogBoxBase_Loaded(object sender, RoutedEventArgs e)
        {
            Height = Application.Current.MainWindow.Height;
            Width = Application.Current.MainWindow.Width;
            Top = Application.Current.MainWindow.Top;
            Left = Application.Current.MainWindow.Left;
/*
            Height = Application.Current.MainWindow.Height - 2;
            Width = 580.0;
            Top = 1 + ((Application.Current.MainWindow.WindowState != WindowState.Maximized) ? Application.Current.MainWindow.Top : 0.0);
            Left = 100 +  ((Application.Current.MainWindow.WindowState != WindowState.Maximized) ? Application.Current.MainWindow.Left : 0);*/
        
        }

        protected override void OnClosed(EventArgs e)
        {
            var vm = DataContext as ViewModelBase;
            if (vm != null)
            {
                vm.Cleanup();
                DataContext = null;
            }

            base.OnClosed(e);
        }
    }
}
